maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=kubeone
pkgver=1.8.3
# Use the latest stable Kubernetes version at the time as the default (https://dl.k8s.io/release/stable-1.30.txt).
# See https://docs.kubermatic.com/kubeone/main/tutorials/creating-clusters/#step-5--provisioning-the-cluster for
# the table of compatible Kubernetes versions.
_k8sver=1.30.5
pkgrel=0
pkgdesc="Automate Kubernetes cluster operations on all platforms"
url="https://kubeone.io/"
arch="all"
license="Apache-2.0"
makedepends="go"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/kubermatic/kubeone/archive/refs/tags/v$pkgver.tar.gz"
options="net" # download Go modules

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	local _goldflags="
	-X k8c.io/kubeone/pkg/cmd.commit=AlpineLinux
	-X k8c.io/kubeone/pkg/cmd.version=$pkgver
	-X k8c.io/kubeone/pkg/cmd.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ" ${SOURCE_DATE_EPOCH:+-d @$SOURCE_DATE_EPOCH})
	-X k8c.io/kubeone/pkg/cmd.defaultKubeVersion=$_k8sver
	-X k8c.io/kubeone/pkg/cmd.defaultCloudProviderName=none
	"

	go build -v -ldflags "$_goldflags"

	mkdir -p man
	./kubeone document man -o man/

	for shell in bash zsh; do
		./kubeone completion $shell > kubeone.$shell
	done
}

check() {
	go test ./pkg/... ./test/...
}

package() {
	install -Dm755 kubeone -t "$pkgdir"/usr/bin/

	install -Dm644 man/*.1 -t "$pkgdir"/usr/share/man/man1/

	install -Dm644 kubeone.bash \
		"$pkgdir"/usr/share/bash-completion/completions/kubeone
	install -Dm644 kubeone.zsh \
		"$pkgdir"/usr/share/zsh/site-functions/_kubeone
}

sha512sums="
5543302d48eaaa27272cc5f3355bc005e52e279569c86c57e8b10f188c70406aebc4d1209034e45ba48ebc5b270d6498bb1471ea21633a002a10213d4ee8b9eb  kubeone-1.8.3.tar.gz
"
